package com.rrx.mapper;
import com.rrx.model.Fault;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;

@Mapper
public interface FaultMapper {

    /**
     * 查询故障类型
     * @return
     */
    @Select("select id,type,faultinfo,deletedfailt from fault where deletedfailt=0 group by type")
    @Results({
            @Result(id=true, property = "id",column ="id"),
            @Result(property = "type",column = "type"),
            @Result(property = "faultinfo",column = "faultinfo"),
            @Result(property = "deletedfailt",column = "deletedfailt"),
    })
    public List<Fault> selectFaultType();
    /**
     * 查询故障信息
     * @param faulttype
     * @return
     */
    @Select("select id,type,faultinfo,deletedfailt from fault where deletedfailt=0 and type=#{type}")
    @Results({
            @Result(id=true, property = "id",column ="id"),
            @Result(property = "type",column = "type"),
            @Result(property = "faultinfo",column = "faultinfo"),
            @Result(property = "deletedfailt",column = "deletedfailt"),
    })
    public List<Fault> selectFaultinfo(@Param("type") String faulttype);

    @Insert("insert into fault (type, faultinfo) values(#{type}, #{info})")
    public int addFault(@Param("type") String type, @Param("info") String info);

    @Select("select * from fault where type = #{type}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "type", property = "type"),
            @Result(column = "faultinfo", property = "faultinfo"),
            @Result(column = "deletedfailt", property = "deletedfailt")
    })
    public Fault[] getFaultByType(@Param("type") String type);

    @Select("select distinct(type) from fault")
    public String[] getFaultType();

    @Update("update fault set type=#{type}, faultinfo=#{info}, deletedfailt=#{state} where id = #{id}")
    public int updateFault(@Param("type") String type, @Param("info") String info, @Param("state") int state, @Param("id") int id);
}


